package com.wyh.book.service;

import com.wyh.book.dao.BookDao;
import com.wyh.book.mapper.BookInfoMapper;
import com.wyh.book.model.BookInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 王圆豪
 * Date: 2025-07-03
 * Time: 10:27
 */
@Service
public class BookService {
    @Autowired
    private BookInfoMapper  bookInfoMapper;

    public List<BookInfo> getList(){
        List<BookInfo> bookInfos = bookInfoMapper.selectAll();
        for (BookInfo book:
                bookInfos) {
            if (book.getStatus() == 1){
                book.setStatusCN("可借阅");
            }else {
                book.setStatusCN("不可借阅");
            }
        }
        return bookInfos;
    }

    public void addBook(BookInfo bookInfo) {
        bookInfoMapper.insertBook(bookInfo);
    }

    public BookInfo queryBookById(Integer id) {
        return bookInfoMapper.selectById(id);
    }

    public void updateBook(BookInfo bookInfo) {
        bookInfoMapper.updateBook(bookInfo);
    }

    public void deleteBook(Integer id) {
        bookInfoMapper.deleteBook(id);
    }

    public void batchDelete(List<Integer> ids) {
        bookInfoMapper.batchDelete(ids);
    }
}
